package com.hh.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.hh.admin.view.ErrorView;
import com.hh.core.entity.ResultEntity;
import com.hh.core.util.BaseUtil;
import com.hh.core.util.HttpCoreUtil;

@Controller 
public class HHErrorController implements ErrorController{

	@Override
	public String getErrorPath() {
		return ErrorView.ERROR_404;
	}

	@RequestMapping(value="/error")
	public ModelAndView Error404(HttpServletRequest request){
		ModelAndView mv = null;
		if(!HttpCoreUtil.assertAjax(request)){//不是ajax请求
			mv = new ModelAndView(ErrorView.ERROR_404);//权限不足
		}else{
			mv = new ModelAndView(new FastJsonJsonView());
			ResultEntity re = new ResultEntity(false,"访问失败","路径不存在");
			mv = BaseUtil.resultMv(mv, re);
		}
		return mv;
	}
}
